package com.oa.srms.apps.business.pay.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.business.pay.IPayInfoService;
import com.oa.srms.apps.constants.IPayStates;
import com.oa.srms.apps.dao.pay.IPayInfoDao;
import com.oa.srms.apps.entity.pay.PayInfoValue;

public class PayInfoServiceImpl implements IPayInfoService {
	
	@Autowired
	private IPayInfoDao payInfoDao;
	@Autowired
	private PayInfoValue payInfoValue;
	

	@Override
	public Integer addPayInfo(String cardId, Double amount, Date payTime, String contents)
			throws Exception {
		
		payInfoValue.setCardId(cardId);
		payInfoValue.setAmount(amount);
		payInfoValue.setPayTime(payTime);
		payInfoValue.setContents(contents);
		payInfoValue.setStates(IPayStates.CHECKING);
		
		return payInfoDao.addPayInfo(payInfoValue);
	}

	@Override
	public void checkPayInfo(Integer id) throws Exception {
		payInfoValue = this.queryById(id);
		payInfoValue.setStates(IPayStates.COMPLETED);
		payInfoDao.editPayInfo(payInfoValue);

	}

	@Override
	public Boolean verifyPayInfo(String cardId) throws Exception {
		List<PayInfoValue> list =payInfoDao.queryPayInfo(cardId);
		if(list!= null && list.size() != 0){
			return true;
		}
		return false;
	}

	@Override
	public PayInfoValue queryById(Integer id) throws Exception {
		return payInfoDao.queryById(id);
	}

	@Override
	public List<PayInfoValue> queryPayInfo(String cardId) throws Exception {
		return payInfoDao.queryPayInfo(cardId);
	}

}
